<template>
  <div>
      <div>
      <el-form  :inline="true" :model="A">
            <el-form-item prop="" label="标题">
                <el-input v-model="A.newsTitle" placeholder="请输入标题内容"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="success" icon="el-icon-search" @click="mhcMessage()">查询</el-button>
            </el-form-item>
            <el-button type="primary" style="margin-left: 300px" @click="tianjia()">消息公告信息</el-button>
        </el-form>
    </div>
      <div>
          <el-table border :data="Data.slice((currentPage-1)*pagesize,currentPage*pagesize)">
            <el-table-column label="标题" prop="newsTitle"></el-table-column>
            <el-table-column prop="newsContent" label="内容"  width="200" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="imgs" label="头像" align="center">
                <template slot-scope="scope">            
                <img :src="scope.row.imgs"  min-width="70" height="70" />
                </template>  
            </el-table-column>
            <el-table-column label="上传者" prop="newsUploader"></el-table-column>
            <el-table-column label="状态" prop="newsState" v-slot="s" align="center">
                <span v-if="s.row.newsState == 0">消息公告</span>
                <span v-if="s.row.newsState == 1">就医指南</span>
            </el-table-column>
            <el-table-column label="创建时间" prop="createTime"></el-table-column>
            <el-table-column label="操作" v-slot="a">
                <el-button type="primary" @click="xiugai(a.row)">修改</el-button>
                <el-button type="primary" @click="shanchu(a.row.id)">删除</el-button>
            </el-table-column>
          </el-table>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[3, 5, 7]"
                :page-size="pagesize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="Data.length">
        </el-pagination>
      </div>
      <div>
          <el-dialog title="添加公告" :visible.sync="addmtk">
              <el-form :model="add">
                <el-form-item label="标题">
                    <el-input v-model="add.newsTitle" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="内容">
                    <el-input v-model="add.newsContent" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="头像">
                    <el-input v-model="add.imgs" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="上传者">
                    <el-input v-model="add.newsUploader" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-button type="primary" @click="MessageAdd()">确定</el-button>
                <el-button type="primary" @click="addmtk=false">取消</el-button>
              </el-form>
          </el-dialog>
      </div>
      <div>
          <el-dialog title="添加公告" :visible.sync="updmtk">
              <el-form :model="upd">
                <el-form-item label="标题">
                    <el-input v-model="upd.newsTitle" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="内容">
                    <el-input v-model="upd.newsContent" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="头像">
                    <el-input v-model="upd.imgs" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="上传者">
                    <el-input v-model="upd.newsUploader" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-button type="primary" @click="MessageUpd()">确定</el-button>
                <el-button type="primary" @click="updmtk=false">取消</el-button>
              </el-form>
          </el-dialog>
      </div>
  </div>
</template>

<script>
export default {
    created(){
        this.findMessageAll();
    },
    data(){
        return{
            Data:[],
            addmtk:false,
            add:{},
            updmtk:false,
            upd:{},
            A:{},
            headertitle: "",
            centerDialogVisible:false,
            pagesize:3,
            currentPage:1,
        }
    },
    methods:{
        findMessageAll(){
            this.$axios.get("/user/user/doctor/ren/findMessageAlls").then(res=>{
                this.Data=res.data.data.list
            })
        },
        tianjia(){
            this.addmtk=true;
        },
        MessageAdd(){
            this.$axios.post("/user/user/doctor/ren/MessageAdds",this.add).then(res=>{
                this.add={};
                this.addmtk=false;
                this.findMessageAll();
            })
        },
        xiugai(row){
            this.updmtk=true;
            this.upd={...row}
         },
        MessageUpd(){
            this.$axios.post("/user/user/doctor/ren/MessageUpds",this.upd).then(res=>{
                this.upd={};
                this.updmtk=false;
                this.findMessageAll();
            })
        },
        shanchu(id){
            this.$axios.get("/user/user/doctor/ren/MessageDels",{params:{id:id}}).then(res=>{
               if(res.data){
                  this.$message({
                      message:'删除成功',
                  })
                  this.findMessageAll() 
               }else{
                   this.$message.error("删除失败")
               }
            
            })
        },
        mhcMessage(){
            this.$axios.get("/user/user/doctor/ren/mhcMessages",{params:{newsTitle:this.A.newsTitle}}).then(res=>{
                this.Data=res.data.data.list
            })
        },
        handleSizeChange(size) {
            this.pagesize = size;
      },
       handleCurrentChange(currentPage) {
            this.currentPage = currentPage;
      
  },
    }
}
</script>

<style>

</style>